import request from '@/utils/request'
import { setUser } from '@/utils/store'

export function loginByUsername(name, password) {
  const data = {
    name, password
  }
  return request({
    url: '/admin/system/index/login',
    method: 'post',
    data
  }).then(res => {
    if (res.code === 200) {
      const temp = res.data
      setUser({ name: temp.name, photo: null, token: temp.token }) // 设置用户的个人数据
    }
    return res
  })
}

export function getInfo(token) {
  return request({
    url: '/admin/system/index/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/admin/system/index/logout',
    method: 'post'
  })
}
